# This file is part of Howlr.
#
# Howlr is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Howlr is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Howlr.  If not, see <http://www.gnu.org/licenses/>.

$APP_NAME ||= 'howlr'
$APP_ROOT ||= File.expand_path(File.dirname(__FILE__)+'/..')

$: << $APP_ROOT+"/lib"

require 'howlr/prep'

Camping.goes :Howlr

Picnic::Logger.init_global_logger!

require 'howlr/views'
require 'howlr/controllers'

# defaults, overridden by your conf file
$CONF[:authentication] ||= {:username => 'howlr', :password => 'howl!'}
$CONF[:mailer] ||= {:delivery_method => 'sendmail'}

module Howlr
  include Howlr::Models
  include Picnic::Authentication

  def self.authenticate(credentials)
    credentials[:username] == $CONF[:authentication][:username] &&
      credentials[:password] == $CONF[:authentication][:password]
  end
end

if $CONF[:authentication]
  Howlr.authenticate_using($CONF[:authentication][:method] || :basic)
end

def Howlr.create
  Howlr::Deliverers::Email::Mailer.delivery_method = $CONF[:mailer][:delivery_method]
  Howlr::Deliverers::Email::Mailer.smtp_settings = $CONF[:mailer][:smtp_settings]
end